﻿; (function ($) {
    $.extend({
        //参考上面，按顺序写参数就行了
        unionSchoolSelect: function (pageParams, extraOptions) {
            LOAD_PROVINCES_URL = '/Common/GetAreas/';
            LOAD_UNIVERSITIES_URL = '/Common/GetUniversities/';
            LOAD_COLLEGES_URL = '/Common/GetColleges/';
            var urls = [LOAD_PROVINCES_URL, LOAD_UNIVERSITIES_URL, LOAD_COLLEGES_URL];
            var paramNames = ['parentId', 'provinceId', 'universityId'];
            return unionSelect(pageParams, urls, paramNames, extraOptions);
        },
        unionAreaSelect: function (pageParams, extraOptions) {
            LOAD_AREAS_URL = '/Common/GetAreas/';
            return unionSelect(pageParams, LOAD_AREAS_URL, null, extraOptions);
        },
        unionIndustrySelect: function (pageParams, extraOptions) {
            LOAD_INDUSTIES_URL = '/Common/GetIndustries';
            return unionSelect(pageParams, LOAD_INDUSTIES_URL, null, extraOptions);
        },
        unionPositionSelect: function (pageParams, extraOptions) {
            LOAD_POSITIONTYPES_URL = '/Common/GetPositionTypes';
            return unionSelect(pageParams, LOAD_POSITIONTYPES_URL, null, extraOptions);
        },
    });

    function unionSelect(pageParams, urls, paramNames, extraOptions) {
        var root, parent, child, option;

        paramNames = paramNames || 'parentId';
        var paramName = typeof(paramNames) == 'string' ? paramNames : null;
        var url = typeof(urls) == 'string' ? urls : null;
        for (var i in pageParams) {
            option = pageParams[i];
            child = {
                selector: option.selector,
                url: url ? url : urls[i],
                urlParamName: paramName ? paramName : paramNames[i],
                selectValue: option.selectValue
            };
            if (i == 0) {
                root = child;
            } else {
                parent.child = child;
            }
            parent = child;
        }

        var plugingConfig = $.extend({
            root: root
        }, extraOptions);

        $.unionSelect(plugingConfig);

        return
    }

})(jQuery)